#+TITLE:Lisp Configuration
#+AUTHOR:Joshua Branson
#+LATEX_HEADER: \usepackage{lmodern}
#+LATEX_HEADER: \usepackage[QX]{fontenc}

This files contains some global keybindings and various settings for Emacs.

* Paredit
:PROPERTIES:
:ID:       06d19157-0295-46c5-be0c-a28074243470
:END:
Paredit tries to balance your parenthesis in your lispy languages.  It is pretty much amazing.

#+BEGIN_SRC emacs-lisp
  (use-package paredit
    :defer t
    :init
    (defun paredit-barf-all-the-way-backward ()
      (interactive)
      (paredit-split-sexp)
      (paredit-backward-down)
      (paredit-splice-sexp))
    (defun paredit-barf-all-the-way-forward ()
      (interactive)
      (paredit-split-sexp)
      (paredit-forward-down)
      (paredit-splice-sexp)
      (if (eolp) (delete-horizontal-space)))
    (defun paredit-slurp-all-the-way-backward ()
      (interactive)
      (catch 'done
        (while (not (bobp))
          (save-excursion
            (paredit-backward-up)
            (if (eq (char-before) ?\()
                (throw 'done t)))
          (paredit-backward-slurp-sexp))))
    (defun paredit-slurp-all-the-way-forward ()
      (interactive)
      (catch 'done
        (while (not (eobp))
          (save-excursion
            (paredit-forward-up)
            (if (eq (char-after) ?\))
                (throw 'done t)))
          (paredit-forward-slurp-sexp)))))
#+END_SRC

I have some specific keybindings for my paredit code
#+BEGIN_SRC emacs-lisp
  (defun elisp/turn-on-paredit ()
      (autoload 'enable-paredit-mode "paredit"
        "Turn on pseudo-structural editing of Lisp code."
        t)
      (define-key emacs-lisp-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
      (define-key emacs-lisp-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
      (define-key emacs-lisp-mode-map (kbd "C-c ]") 'paredit-forward-barf-sexp)
      (define-key emacs-lisp-mode-map (kbd "C-c [") 'paredit-backward-barf-sexp)

      (define-key emacs-lisp-mode-map (kbd "C-c )") 'paredit-slurp-all-the-way-forward)
      (define-key emacs-lisp-mode-map (kbd "C-c }") 'paredit-barf-all-the-way-forward)
      (define-key emacs-lisp-mode-map (kbd "C-c (") 'paredit-slurp-all-the-way-backward)
      (define-key emacs-lisp-mode-map (kbd "C-c {") 'paredit-barf-all-the-way-backward)
      (evil-define-key 'normal evil-dvorak-mode-map (kbd "k") 'paredit-kill)
      ;;(evil-paredit-mode +1)
  )

  (defun scheme/turn-on-paredit ()
      (autoload 'enable-paredit-mode "paredit"
        "Turn on pseudo-structural editing of Lisp code."
        t)
      (define-key scheme-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
      (define-key scheme-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
      (define-key scheme-mode-map (kbd "C-c ]") 'paredit-forward-barf-sexp)
      (define-key scheme-mode-map (kbd "C-c [") 'paredit-backward-barf-sexp)

      (define-key scheme-mode-map (kbd "C-c )") 'paredit-slurp-all-the-way-forward)
      (define-key scheme-mode-map (kbd "C-c }") 'paredit-barf-all-the-way-forward)
      (define-key scheme-mode-map (kbd "C-c (") 'paredit-slurp-all-the-way-backward)
      (define-key scheme-mode-map (kbd "C-c {") 'paredit-barf-all-the-way-backward)
      (evil-define-key 'normal evil-dvorak-mode-map (kbd "k") 'paredit-kill)
      ;;(evil-paredit-mode +1)
  )
#+END_SRC
** requiring evil-paredit
:PROPERTIES:
:ID:       5bfbb5ea-9686-4982-9c0a-1439cdf98acd
:END:
   Evil-paredit is not available on melpa.  I should probably fix this.

:PROPERTIES:
:ID:       88eceed3-f78d-4616-88ff-ae3902d0c13e
:END:

#+BEGIN_SRC emacs-lisp
(require 'evil-paredit)
#+END_SRC

** hooking in paredit and some other cool modes
:PROPERTIES:
:ID:       13f62e23-572a-408b-856b-3e5b55fbaa7e
:END:
#+BEGIN_SRC emacs-lisp
  (add-hook 'emacs-lisp-mode-hook '(lambda ()
                                     (rainbow-delimiters-mode 1)
                                     ;; You want to enable evil-paredit mode for evil, because it's SOOO helpful.
                                     (evil-paredit-mode 1)
                                     (elisp/turn-on-paredit)
                                     ;; make >= look like ≥
                                     (push '(">=" . ?≥) prettify-symbols-alist)
                                     (push '("<=" . ?≤) prettify-symbols-alist)
                                     (push '("float-pi" . ?π) prettify-symbols-alist)
                                     (push '("float-pi" . ?e) prettify-symbols-alist)))


(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
(add-hook 'emacs-lisp-mode-hook       #'enable-paredit-mode)
(add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
(add-hook 'ielm-mode-hook             #'enable-paredit-mode)
(add-hook 'lisp-mode-hook             #'enable-paredit-mode)
(add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
(add-hook 'scheme-mode-hook           #'enable-paredit-mode)

(add-hook 'scheme-mode-hook 'evil-paredit-mode)
(add-hook 'scheme-mode-hook 'scheme/turn-on-paredit)
#+END_SRC

** Paredit and scheme
:PROPERTIES:
:ID:       9a19b41b-3a98-42a5-b02d-da8a2fd52553
:END:
#+BEGIN_SRC emacs-lisp
  (defun scheme/turn-on-paredit ()
    (autoload 'enable-paredit-mode "paredit"
      "Turn on pseudo-structural editing of Lisp code."
      t)
    (define-key scheme-mode-map (kbd "C-c 0") 'paredit-forward-slurp-sexp)
    (define-key scheme-mode-map (kbd "C-c 9") 'paredit-backward-slurp-sexp)
    (define-key scheme-mode-map (kbd "C-c ]") 'paredit-forward-barf-sexp)
    (define-key scheme-mode-map (kbd "C-c [") 'paredit-backward-barf-sexp)

    (define-key scheme-mode-map (kbd "C-c )") 'paredit-slurp-all-the-way-forward)
    (define-key scheme-mode-map (kbd "C-c }") 'paredit-barf-all-the-way-forward)
    (define-key scheme-mode-map (kbd "C-c (") 'paredit-slurp-all-the-way-backward)
    (define-key scheme-mode-map (kbd "C-c {") 'paredit-barf-all-the-way-backward)
    (evil-define-key 'normal evil-dvorak-mode-map (kbd "k") 'paredit-kill)
    (paredit-mode +1))
#+END_SRC

#+BEGIN_SRC emacs-lisp
  (add-hook 'scheme-mode-hook '(lambda ()
                                 (rainbow-delimiters-mode 1)
                                 ;; You want to enable evil-paredit mode for evil, because it's SOOO helpful.
                                 (evil-paredit-mode 1)
                                 (scheme/turn-on-paredit)
                                 ;; make >= look like ≥
                                 (push '(">=" . ?≥) prettify-symbols-alist)
                                 (push '("<=" . ?≤) prettify-symbols-alist)))
#+END_SRC

** geiser-mode (scheme repls)
:PROPERTIES:
:ID:       8406082e-dd86-4eea-9806-7c487b7f2c0a
:END:
Install geiser mode for guile code

#+BEGIN_SRC emacs-lisp
  (use-package geiser
    :defer t
    :config
    (setq geiser-active-implementations '(guile)))
#+END_SRC

* open .sxml files in scheme

  #+BEGIN_SRC emacs-lisp
    (use-package scheme-mode
      :mode
      ("\\.sxml\\'" . scheme-mode))
  #+END_SRC
* COMMENT things I don't use
** COMMENT easy-escape for regexps in emacs lisp
:PROPERTIES:
:ID:       b3aad618-a1aa-4149-b658-2c23cb7da2ac
:END:

This mode really confuses me.  I'm turning it off.

emacs regexp are cumbersome
"\b" in most regexp engines means word end
but when one is programming in emacs-lisp you have to write "\\b"
easy escape is light prettify-mode and changes \\ --> one highlighted \
#+BEGIN_SRC emacs-lisp
(use-package easy-escape
:config (add-hook 'emacs-lisp-mode-hook #'easy-escape-minor-mode)
:diminish easy-escape-minor-mode)
#+END_SRC

** COMMENT highlight t and nil in emacs lisp
:PROPERTIES:
:ID:       000b010d-6d3a-4f5c-b6d7-2aa6228d2f2c
:END:

#+BEGIN_SRC emacs-lisp
  (defun getBufferStringFromWordAtPoint ()
    "This function gets the buffer string from the word at point"
    (interactive)
    (print
     (buffer-substring (progn
                         (backward-word)
                         (point))
                       (progn
                         (forward-word)
                         (point)))))
#+END_SRC



font-lock-constant-face is defined [[file:/usr/share/emacs/24.5/lisp/font-lock.el.gz::(defface%20font-lock-constant-face][here]], but for whatever reason, I can't seem to use it in Emacs lisp mode.  Why?

#+BEGIN_SRC emacs-lisp
  (defface font-lock-green-color
    '((t (:foreground "#00ff00")))
    "For boolean values")

  (defun highlightBoolsElisp ()
    "This highlights the boolean values in elisp."
    (interactive)
    (font-lock-add-keywords nil
                            '(("\\<t\\>" 1 'font-lock-green-color prepend)
                              ("\\<nil\\>" 1 'font-lock-green-color prepend))))



    ;;(add-hook 'emacs-lisp-mode-hook #'highlightBoolsElisp)

#+END_SRC

#+BEGIN_SRC emacs-lisp
(provide 'init-lisp)
#+END_SRC

** COMMENT Automatic byte compilation
 #+BEGIN_SRC emacs-lisp
(use-package auto-compile
  )
(auto-compile-on-save-mode 1)
(auto-compile-on-load-mode 1)
 #+END_SRC

 Load .el if newer than corresponding .elc
 #+BEGIN_SRC emacs-lisp
(setq load-prefer-newer t)
 #+END_SRC
** COMMENT Parinfer

I can't figure out how to get parinfer to work...It makes writing lispy code hard and not fun.

#+BEGIN_SRC emacs-lisp :tangle no
(use-package parinfer

  :bind
  (("C-," . parinfer-toggle-mode))
  :init
  (progn
    (setq parinfer-extensions
          '(defaults       ; should be included.
            pretty-parens  ; different paren styles for different modes.
            evil           ; If you use Evil.
            ;;lispy          ; If you use Lispy. With this extension, you should install Lispy and do not enable lispy-mode directly.
            paredit        ; Introduce some paredit commands.
            smart-tab      ; C-b & C-f jump positions and smart shift with tab & S-tab.
            smart-yank))   ; Yank behavior depend on mode.
    (add-hook 'clojure-mode-hook #'parinfer-mode)
    (add-hook 'emacs-lisp-mode-hook #'parinfer-mode)
    (add-hook 'common-lisp-mode-hook #'parinfer-mode)
    (add-hook 'scheme-mode-hook #'parinfer-mode)
    (add-hook 'lisp-mode-hook #'parinfer-mode)))
#+END_SRC

* reload defun at point
:PROPERTIES:
:ID:       98fc549d-772e-4ff0-beb1-98be6cf7fbe1
:END:

#+BEGIN_SRC emacs-lisp
  (defun my/reeval-defun-at-point ()
      "This reevaluates the defun at point."
      (interactive)
      (let (current-pos-of-point)
        (setq current-pos-of-point (point))
        (search-backward-regexp "^.*(defun\\|^(defun")
        (evil-jump-item)
        (eval-last-sexp)
        (goto-char current-pos-of-point)))

    (define-key emacs-lisp-mode-map (kbd "C-x e") #'my/reeval-defun-at-point)

    #+END_SRC

* provide this file
:PROPERTIES:
:ID:       a9e16be2-e2dd-4825-95c1-f86efdbadd74
:END:
#+BEGIN_SRC emacs-lisp
(provide 'init-lisp)
#+END_SRC
